#ifndef __GLF_TASK_TASKTHREAD_IMPL_H_INCLUDED__
#define __GLF_TASK_TASKTHREAD_IMPL_H_INCLUDED__

#include <glf/task/taskThread.h>
#include <glf/task/taskHandler.h>
#include <glf/app.h>

namespace glf {

template<typename Tag1, typename Tag2>
TaskThread<Tag1, Tag2>::TaskThread(void*)
{
}

template<typename Tag1, typename Tag2>
TaskThread<Tag1, Tag2>::~TaskThread()
{
}

template<typename Tag1, typename Tag2>
void TaskThread<Tag1, Tag2>::Run()
{
	glf::ScopedReserveContext reservedContext;
		
	TaskCondition tc;
	SetTaskCondition(tc);

	TaskHandler<Tag1> th1(&tc);
	TaskHandler<Tag2> th2(&tc);

	while(IsActive())
	{
		th1.Consume();
		th2.Consume();

		tc.Wait();
	}
}

template<typename Tag1>
TaskThread<Tag1, null_t>::TaskThread(void*)
{
}

template<typename Tag1>
TaskThread<Tag1, null_t>::~TaskThread()
{
}

template<typename Tag1>
void TaskThread<Tag1, null_t>::Run()
{
	glf::ScopedReserveContext reservedContext;

	TaskCondition tc;
	SetTaskCondition(tc);

	TaskHandler<Tag1> th1(&tc);

	while(IsActive())
	{
		th1.Consume();

		tc.Wait();
	}
}

} // end namespace glf

#endif // __GLF_TASK_TASKTHREAD_IMPL_H_INCLUDED__
